package org.csu.mybigpro.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.csu.mybigpro.domain.OperationLog;
import org.csu.mybigpro.persistence.OperationLogMapper;
import org.csu.mybigpro.service.OperationLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OperationLogServiceImpl implements OperationLogService {
    @Autowired
    private OperationLogMapper operationLogMapper;

    @Override
    public void save(OperationLog log) {
        operationLogMapper.insert(log);
    }

    @Override
    public Page<OperationLog> getLogsByCondition(String username, String type, String start, String end, int page, int size) {
        QueryWrapper<OperationLog> wrapper = new QueryWrapper<>();
        if (username != null) wrapper.like("username", username);
        if (type != null) wrapper.eq("operation_type", type);
        if (start != null && end != null) wrapper.between("create_time", start, end);
        return operationLogMapper.selectPage(new Page<>(page, size), wrapper);
    }
}
